package com.smmisia.article.factory;

import com.smmisia.article.enums.FriendEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class FriendStatusFactory implements InitializingBean {

    @Autowired
    private List<FriendStrategy> friendStrategies;

    private Map<FriendEnum, FriendStrategy> friendStrategyMap = new HashMap<>();

    @Override
    public void afterPropertiesSet() throws Exception {
        for (FriendStrategy friendStrategy : friendStrategies) {
            friendStrategyMap.put(friendStrategy.getFriendEnum(), friendStrategy);
        }
    }

    public FriendStrategy getFriendStrategy(int code) {
        FriendEnum anEnum = FriendEnum.getEnum(code);
        return friendStrategyMap.get(anEnum);
    }
}
